import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/routers/fluro_navigator.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/util/theme_utils.dart';
import 'package:flutter_deer/widgets/my_app_bar.dart';
import 'package:flutter_deer/widgets/my_button.dart';
import 'package:flutter_deer/widgets/my_scroll_view.dart';
import 'package:flutter_deer/widgets/selected_image.dart';
import 'package:flutter_deer/widgets/text_field_item.dart';
import 'package:image_picker/image_picker.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:flutter_deer/routers/routers.dart';
import 'package:flutter_gen/gen_l10n/deer_localizations.dart';

class StoreAuditPage extends StatefulWidget {
  const StoreAuditPage({super.key});

  @override
  _StoreAuditPageState createState() => _StoreAuditPageState();
}

class _StoreAuditPageState extends State<StoreAuditPage> {
  final GlobalKey<SelectedImageState> _imageGlobalKey =
      GlobalKey<SelectedImageState>();
  final FocusNode _nodeText1 = FocusNode();
  final FocusNode _nodeText2 = FocusNode();
  final FocusNode _nodeText3 = FocusNode();
  final ImagePicker picker = ImagePicker();

  KeyboardActionsConfig _buildConfig(BuildContext context) {
    return KeyboardActionsConfig(
      keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
      keyboardBarColor: ThemeUtils.getKeyboardActionsColor(context),
      actions: [
        KeyboardActionsItem(
          focusNode: _nodeText1,
          displayDoneButton: false,
        ),
        KeyboardActionsItem(
          focusNode: _nodeText2,
          displayDoneButton: false,
        ),
        KeyboardActionsItem(
          focusNode: _nodeText3,
          toolbarButtons: [
            (node) {
              return GestureDetector(
                onTap: () => node.unfocus(),
                child: Padding(
                  padding: const EdgeInsets.only(right: 16.0),
                  child: Text('${DeerLocalizations.of(context)!.close.nullSafe}'),
                ),
              );
            },
          ],
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: '${DeerLocalizations.of(context)!.personalInformation.nullSafe}',
      ),
      body: MyScrollView(
        padding: const EdgeInsets.symmetric(vertical: 16.0),
        keyboardConfig: _buildConfig(context),
        tapOutsideToDismiss: true,
        bottomButton: Padding(
          padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 8.0),
          child: MyButton(
            onPressed: () {
                  NavigatorUtils.push(context, Routes.home, clearStack: true);
              // NavigatorUtils.push(context, StoreRouter.auditResultPage);
            },
            text: '提交',
          ),
        ),
        children: _buildBody(),
      ),

      /// 同时存在底部按钮与keyboardConfig配置时，为保证Android与iOS平台软键盘弹出高度正常，添加下面的代码。
      resizeToAvoidBottomInset: defaultTargetPlatform != TargetPlatform.iOS,
    );
  }

  List<Widget> _buildBody() {
    return [
      Gaps.vGap5,
      Padding(
        padding: EdgeInsets.only(left: 16.0),
        child: Text('${DeerLocalizations.of(context)!.personalIdentityInformation.nullSafe}', style: TextStyles.textBold18),
      ),
      Gaps.vGap16,
      Center(
        child: SelectedImage(
          key: _imageGlobalKey,
        ),
      ),
      Gaps.vGap10,
      Center(
        child: Text(
          '${DeerLocalizations.of(context)!.playerAvatar.nullSafe}',
          style: Theme.of(context)
              .textTheme
              .titleSmall
              ?.copyWith(fontSize: Dimens.font_sp14),
        ),
      ),
      Gaps.vGap16,
      Gaps.vGap32,
      Padding(
        padding: EdgeInsets.only(left: 16.0),
        child: Text('${DeerLocalizations.of(context)!.playerInfomation.nullSafe}', style: TextStyles.textBold18),
      ),
      Gaps.vGap16,
      TextFieldItem(focusNode: _nodeText2, title: '${DeerLocalizations.of(context)!.playerNickname.nullSafe}', hintText: '${DeerLocalizations.of(context)!.playerNicknameTip.nullSafe}'),
      TextFieldItem(
          focusNode: _nodeText3,
          keyboardType: TextInputType.phone,
          title: '${DeerLocalizations.of(context)!.telephone.nullSafe}',
          hintText: '${DeerLocalizations.of(context)!.telephoneTip.nullSafe}')
    ];
  }

}
